<template>
	<view class="page">
		<view class="list-box">
			<view class="item-box" v-for="(item,index) in listData" :key="item.id" @tap="goDetail(item.id)">
				<image class="cover" :src="item.scene_pic_url"></image>
				<view class="title">{{item.title}}</view>
			</view>
		</view>
		<uni-load-more :status="loadStatus" :showText="pageParams.isLoadEnd && listData.length > 1"></uni-load-more>
		<tab-bar/>
	</view>
</template>

<script>
	import {getSeedingListApi} from '@/api/seeding.js'
	export default {
		data() {
			return {
				loadStatus: 'more',
				pageParams: {
					page: 1,
					isLoadEnd: false
				},
				listData: []
			}
		},
		onLoad() {
			uni.hideTabBar()
			this.getListData()
		},
		onPullDownRefresh() {
			this.pageParams.page = 1
			this.pageParams.isLoadEnd = false
			this.getListData()
		},
		onReachBottom() {
			if(this.pageParams.isLoadEnd) return
			this.pageParams.page++
			this.getListData()
		},
		methods: {
			goDetail(id) {
				uni.navigateTo({
					url: `/pages/aPackage/articleDetail/articleDetail?id=${id}`
				})
			},
			async getListData() {
				this.loadStatus = 'loading'
				const res = await getSeedingListApi({
					page: this.pageParams.page
				})
				uni.stopPullDownRefresh()
				this.loadStatus = 'more'
				if(this.pageParams.page < 10) {
					this.pageParams.isLoadEnd = true
					this.loadStatus = 'no-more'
				}
				if(this.pageParams.page === 1) {
					this.listData = res.data.data
				}else {
					this.listData = this.listData.concat(res.data.data)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
	}
	.list-box {
		.item-box {
			.cover {
				width: 750rpx;
				height: 400rpx;
			}
			.title {
				font-size: 32rpx;
				color: #333333;
				text-align: center;
				padding: 20rpx;
				box-sizing: border-box;
				line-height: 48rpx;
			}
		}
	}
</style>